package main

import (
	"fmt"
	"strconv"
	"time"

	"gobot.io/x/gobot/drivers/gpio"
	"gobot.io/x/gobot/platforms/raspi"
)

func main() {
	// Sin()
	var nu string
	r := raspi.NewAdaptor()

	// led := gpio.NewLedDriver(r, "19")
	stepper := gpio.NewStepperDriver(r, [4]string{"22", "24", "26", "28"}, gpio.StepperModes.DualPhaseStepping, 2048)
	m := stepper.GetMaxSpeed()
	fmt.Println(m)
	for {
		time.Sleep(time.Millisecond * 200)

		fmt.Println("Input the step:")
		fmt.Scanln(&nu)
		i, _ := strconv.Atoi(nu)

		// led.Toggle()

		//set spped
		stepper.SetSpeed(uint(i))

		//Move forward one revolution
		if err := stepper.Move(2048); err != nil {
			fmt.Println(err)
		}

		//Move backward one revolution
		if err := stepper.Move(-2048); err != nil {
			fmt.Println(err)
		}
		_ = stepper.Halt()
	}

	// work := func() {
	// 	gobot.Every(200*time.Millisecond, func() {
	// 		led.Toggle()
	// 	})
	// }

	// robot := gobot.NewRobot("blinkBot",
	// 	[]gobot.Connection{r},
	// 	[]gobot.Device{led},
	// 	work,
	// )

	// robot.Start()
}
